<?php

namespace App\Http\Controllers\Api\Admin;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use App\Facades\Services\Admin\ArticleService;
use App\Facades\Utils\ValidateParameter;

class ArticleController extends Controller
{
    public function create(Request $request){
        $rules = [
            'title' => 'required',
            'abstract' => 'required',
            'cover' => 'required',
            'content' => 'required'
        ];

        ValidateParameter::validate($request,$rules);

        $data = $request->all();

        ArticleService::createArticle($data);

        return formatJsonResponse();
    }

    public function update(Request $request){

         $rules = [
            'id' => 'required|exists:articles,id',
            'title' => 'required',
            'abstract' => 'required',
            'content' => 'required'
        ];

        ValidateParameter::validate($request,$rules);

        $data = $request->all();

        ArticleService::updateArticle($data);

        return formatJsonResponse();
    }

    public function delete(Request $request){

        $rules = [
            'id' => 'required|exists:articles,id'
        ];

        ValidateParameter::validate($request,$rules);

        $data = $request->all();

        ArticleService::deleteArticle($data);

        return formatJsonResponse();
    }
}
